package ddz;

/**
 * 这个是玩家的实体类
 *
 * @author Bison
 */
public class Person {
	private int[] person1 = new int[20];
	private int[] person2 = new int[17];
	private int[] person3 = new int[17];

	// 余下三张属于地主的
	private int[] threePukes = new int[3];

	public Person() {
		Cards mCards = Cards.getInstance();
		personHold(mCards.pukes);
	}

	/**
	 * 分牌
	 */
	private void personHold(int[] pukes) {
		int k = 0;
		for (int i = 0; i < 3; i++) {
			if (i == 0) {
				for (int j = 0; j < 17; j++) {
					person1[j] = pukes[k++];
				}
				person1[17] = pukes[51];
				person1[18] = pukes[52];
				person1[19] = pukes[53];
				// 将其排序
				sort(person1);
			}
			if (i == 1) {
				for (int j = 0; j < 17; j++) {
					person2[j] = pukes[k++];
				}
				// 将其排序
				sort(person2);
			}
			if (i == 2) {
				for (int j = 0; j < 17; j++) {
					person3[j] = pukes[k++];
				}
				// 将其排序
				sort(person3);
			}
		}
		threePukes[0] = pukes[51];
		threePukes[1] = pukes[52];
		threePukes[2] = pukes[53];
		
	}

	/**
	 * 对每个玩家手里的牌排序:使用冒泡排序
	 */
	private void sort(int[] ary) {
		for (int i = 0; i < ary.length; i++) {
			for (int j = 0; j < ary.length - i - 1; j++) {
				if (ary[j] > ary[j + 1]) {
					int temp = ary[j];
					ary[j] = ary[j + 1];
					ary[j + 1] = temp;
				}
			}
		}
	}

	public int[] getPerson1() {
		return person1;
	}

	public int[] getPerson2() {
		return person2;
	}

	public int[] getPerson3() {
		return person3;
	}

	public int[] getThreePukes() {
		return threePukes;
	}
	public static void main(String[] args) {
		String [] strings = Utils.getPukes();
		for(int i=0;i<strings.length;i++) {
			System.out.println(strings[i]);
		}
	}
}